'use strict';
const { DataTypes } = require('sequelize');
const sequelize = require('../config/db');

const PunchRecord = sequelize.define('punch_record', {
  punchPlanId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '打卡计划ID'
  },
  dayNo: {
    type: DataTypes.STRING(8),
    allowNull: false,
    comment: '打卡日期，格式类似20250101'
  },
  detail: {
    type: DataTypes.STRING(100),
    allowNull: true,
    comment: '打卡详细描述，字数限制100'
  }
}, {
  timestamps: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at'
});

// 添加associate方法，而不是直接定义关联
PunchRecord.associate = function(models) {
  PunchRecord.belongsTo(models.PunchPlan, { foreignKey: 'punchPlanId' });
};

module.exports = PunchRecord;
